package com.fz.vo;

import com.fz.core.ResultCode;
import lombok.Getter;

@Getter // 要写get方法
public class ResultVo<T> {
    private final Integer code;
    private final T content;
    private final String message;


    public ResultVo(Integer code, T content, String message) {
        this.code = code;
        this.content = content;
        this.message = message;
    }

    public static <T> ResultVo<T> getInstance(ResultCode resultCode, T content, String message) {
        return new ResultVo<>(resultCode.getValue(), content, message);
    }

    public static <T> ResultVo<T> success(T content, String message) {
        return getInstance(ResultCode.SUCCESS, content, message);
    }
    // 查询成功时，不会有消息
    public static <T> ResultVo<T> success(T content) {
        return success(content, null);
    }

    public static <T> ResultVo<T> failed(T content, String message) {
        return getInstance(ResultCode.FAILED, content, message);
    }
    // 遇到错误时，可能没有返回值，但是会有消息
    public static <T> ResultVo<T> failed(String message) {
        return failed(null, message);
    }
}
